﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using BCGC.BLL.Forum;
using Jalal.Library.DataStructure;
using System.Reflection;

public partial class recent_posts : PublicBasePage
{
    public int ID
    {
        get
        {
            if (string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["id"]) == false)
                return Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);

            return -1;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadPagerSettings();
            LoadData();
        }
    }

    private void LoadPagerSettings()
    {
        customPager1.SortOrder = "LatestPostDate";
        customPager1.CurrentPage = 1;

        customPager2.SortOrder = "LatestPostDate";
        customPager2.CurrentPage = 1;
    }

    private void LoadData()
    {
        
        PostCategory category = ForumManager.GetPostCategoryByID(ID);
        if(category!=null)
        {
            litCategory.Text = category.CategoryName;
            litCategoryDescription.Text =Server.HtmlDecode(category.Description);
            LoadGridData();
        }
    }
    protected void imbStartTopic_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect(CustomSiteMap.StartTopic+"?cat="+ID);
    }
    private void LoadGridData()
    {
        int totalCount = 0;
        ReadWriteCustomCollection<LatestPosts> posts = ForumManager.GetAllLatestPost(ID, customPager1.SortOrder, "DESC", customPager1.CurrentPage, customPager1.PageSize, out totalCount);
        customPager1.TotalItems = totalCount;
        customPager1.LoadPager();

        customPager2.TotalItems = customPager1.TotalItems;
        customPager2.LoadPager();

        grvPosts.DataSource = posts;
        grvPosts.DataBind();
    }
    protected void lkbPageIndex_Command(object sender, CommandEventArgs e)
    {
        customPager1.CurrentPage = Convert.ToInt32(e.CommandArgument);
        customPager2.CurrentPage = Convert.ToInt32(e.CommandArgument);
        LoadGridData();
    }

    protected void lkbPageIndexBottom_Command(object sender, CommandEventArgs e)
    {
        customPager1.CurrentPage = Convert.ToInt32(e.CommandArgument);
        customPager2.CurrentPage = Convert.ToInt32(e.CommandArgument);
        LoadGridData();
    }
}
